//
//  CCSDSortView.m
//  Ccsd_user
//
//  Created by 张露杰 on 18/2/24.
//  Copyright © 2018年 张露杰. All rights reserved.
//

#import "CCSDSortView.h"

@implementation CCSDSortView
{
    NSString *_title;
}

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self) {
        self.isSelect = NO;
        [self creatViewWithTitle:title];
        [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)]];
    }
    return self;
}

-(void)creatViewWithTitle:(NSString *)title
{
    for (UIView *view in self.subviews) {
        [view removeFromSuperview];
    }
    _title = title;
    UILabel *titleLabel = [TomamaUI createLabel:CGRectMake(0, 0, [TomamaUI getStringWeithtWith:title andHeigth:14*screenW_6 andFont:[UIFont systemFontOfSize:14*screenW_6]], 14*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:14*screenW_6] textColor:TextBlack text:title];
    [self addSubview:titleLabel];
    titleLabel.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
    
    NSString *imageName = @"Main_search_down";
    if (_isSelect) {
        imageName = @"Main_search_up";
    }
    _imageV = [TomamaUI createImageView:CGRectMake(CGRectGetMaxX(titleLabel.frame) + 6*screenW_6, 0, 7.5*screenW_6, 4.5*screenW_6) backGroundImageV:imageName];
    [self addSubview:_imageV];
    _imageV.center = CGPointMake(_imageV.center.x, titleLabel.center.y);
}

-(void)click
{
    _isSelect = !_isSelect;
    [self creatViewWithTitle:_title];
    if (_isSelect) {
        if (_chouseComplete) {
            _chouseComplete();
        }
    }else{
        if (_unChouseComplete) {
            _unChouseComplete();
        }
    }
}

@end
